package com.mathdroid.core;

import com.mathdroid.exceptionhandling.ExceptionHandler;
import com.mathdroid.gui.main.DroidFrame;
import com.mathdroid.gui.splashscreen.SplashScreen;
import com.mathdroid.model.EModelObserverEvent;
import com.mathdroid.model.Model;
import com.mathdroid.model.Profile;
import com.mathdroid.model.enums.ESpec;

/**
 * This is the entrance point of the program. While showing the splash screen
 * the data is loaded and the user interface is built.
 */
public final class Main {

	/**
	 * Hidden standard constructor.
	 */
	private Main() { }

	/**
	 * Runs the Droid. Loads the model and builds the UI.
	 * @param args No arguments.
	 */
	public static void main(final String[] args) {

		SplashScreen splashSreen = null;

		try {
			splashSreen = new SplashScreen();
			new Setup();
			Profile p = new Profile("Unknown", ESpec.SNIPER);
			Model.setProfile(p);
			DroidFrame f = new DroidFrame();
			Model.setDroidFrame(f);
			Model.fireEvent(EModelObserverEvent.PROFILE_LOADED);
			f.setVisible(true);
			splashSreen.dispose();
		} catch (Exception e) {
			ExceptionHandler.report("Unhandled exception.", e);
			if (splashSreen != null) {
				splashSreen.dispose();
			}
		}
	}

}
